<?php

namespace App\Admin\Controllers;

use App\Models\Student;
use App\Models\Squad;

use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class StudentReportController extends Controller
{

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index(Request $request)
    {
        $class = new Admin();
        $class::disablePjax();
        return Admin::content(function (Content $content) use($request){
            $content->header(trans('admin.student'));
            $content->description(trans('admin.list'));
            $content->row($this->form($request));
            $content->row($this->view());
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {

    }

    /**
     * Show interface.
     *
     * @param mixed   $id
     * @param Content $content
     *
     * @return Content
     */
    public function show($id, Content $content)
    {

    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {

    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {

    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form($request)
    {
        return Admin::form(Squad::class,function (Form $form) use ($request) {
            $form->setTitle('查看');

            $form->row(function ($row) use ($form,$request)
            {
                $row->width(4)->text('student','学生')->attribute(['id'=>'student','student_id'=>$request['id'],'disabled'=>'disabled'])->default(function() use ($request){
                    return Student::find($request['id'])->en_name;
                });
                //$row->width(4)->text('start_time','开始时间(包含)')->attribute(['id'=>'startTime']);
                //$row->width(4)->text('end_time','结束时间(包含)')->attribute(['id'=>'endTime']);
                $row->width(4)->date('start_time','开始时间(包含)')->attribute(['id'=>'startTime','style'=>'width:350px;'])->default(date('Y-m-d',strtotime('-1 month')));
                $row->width(4)->date('end_time','结束时间(包含)')->attribute(['id'=>'endTime','style'=>'width:350px;'])->default(date('Y-m-d'));
            },  $form);

            $form->row(function ($row) use ($form)
            {
                $status = array();
                /*                $status[1] = array('1'=>'听写');
                                $status[2] = array('2'=>'测验');
                                $status[3] = array('3'=>'考勤');
                                $status[4] = array('4'=>'家校');
                                $status[5] = array('5'=>'作业');*/
                $status = array('1'=>'听写','2'=>'测验','3'=>'考勤','4'=>'家校','5'=>'作业');
                $row->width(4)->multipleSelect('type','类型')->options($status)
                    ->attribute(['id'=>'type','disabled'=>'true'])->default(['1','2','3','4','5']);
                $row->width(4)->html('<button style="margin-left:150px;" type="button" id="btn_submit" class="btn btn-primary">查询</button><button style="" type="button" id="btn_pdf" onclick="o_window()" class="btn btn-danger">导出PDF</button>');
            },  $form);

            $form->disableSubmit();
            $form->disableReset();
            $form->tools(function (Form\Tools $tools) {
                // 去掉`列表`按钮
                $tools->disableList();
                // 去掉`删除`按钮
                $tools->disableDelete();
                // 去掉`查看`按钮
                $tools->disableView();
            });
        });
    }

    protected function view()
    {
        return view('admin.student_report');
    }

}
